var e = require;
var t = module;
var o = exports;
var n = o;
Object.defineProperty(n, "__esModule", {value: !0});
var i = e("GlobalParam"),
    a = e("Util"),
    r = e("RankProxy"),
    s = e("RankProxy2"),
    c = e("GameData"),
    l = (function () {
        function e() {
            (this.AIList = []), (this.AIIcon = {}), (this.tt_isLoadUserIcon = !1);
        }
        return (
            Object.defineProperty(e, "instance", {
                get: function () {
                    return e._instance || (e._instance = new e()), e._instance;
                },
                enumerable: !1,
                configurable: !0
            }),
            (e.getVerticalVector = function (e) {
                var t = -e.y / e.x;
                return cc.v2(t, 1).normalize();
            }),
            (e.vectorToAngle = function (e) {
                var t = Math.atan2(e.y, e.x);
                return cc.misc.radiansToDegrees(t);
            }),
            (e.angleToVector = function (e) {
                var t = 15 * Math.cos((3.14 * e) / 180),
                    o = 15 * Math.sin((3.14 * e) / 180);
                return cc.v2(t, o).normalize();
            }),
            (e.getAngleByThreePos = function (e, t, o) {
                var n = Math.sqrt(Math.pow(e.x - t.x, 2) + Math.pow(e.y - t.y, 2)),
                    i = Math.sqrt(Math.pow(e.x - o.x, 2) + Math.pow(e.y - o.y, 2)),
                    a = Math.sqrt(Math.pow(t.x - o.x, 2) + Math.pow(t.y - o.y, 2)),
                    r = (Math.pow(n, 2) + Math.pow(i, 2) - Math.pow(a, 2)) / (2 * n * i);
                return Math.round((180 * Math.acos(r)) / Math.PI);
            }),
            (e.GetAngleWith360 = function (e, t, o) {
                var n = t.x - e.x,
                    i = t.y - e.y,
                    a = o.x - e.x,
                    r = o.y - e.y,
                    s = (n * a + i * r) / (Math.sqrt(n * n + i * i) * Math.sqrt(a * a + r * r));
                s < -1 ? (s = -1) : s > 1 && (s = 1);
                var c = (180 * Math.acos(s)) / Math.PI,
                    l = cc.v3(t.x - e.x, t.y - e.y, 0),
                    d = cc.v3(o.x - e.x, o.y - e.y, 0);
                return l.x * d.y - d.x * l.y < 0 && (c = 360 - c), c;
            }),
            (e.GetResurrectionPos = function () {
                return [
                    cc.v3(0, 0, 0),
                    cc.v3(-1e3, -1e3, 0),
                    cc.v3(-1e3, 0, 0),
                    cc.v3(-1e3, 1e3, 0),
                    cc.v3(1e3, -1e3, 0),
                    cc.v3(1e3, 0, 0),
                    cc.v3(1e3, 1e3, 0),
                    cc.v3(0, -1e3, 0),
                    cc.v3(0, 1e3, 0)
                ];
            }),
            (e.GetAIPos = function () {
                var e = a.default.randomFrom(0, 360),
                    t = this.angleToVector(e);
                return cc.v3(2500 * t.x, 2500 * t.y, 0);
            }),
            (e.GetFoodRandType = function () {
                var e = a.default.randomFrom(1, 100);
                return e > 95
                    ? c.FoodType.Magnet
                    : e > 90
                    ? c.FoodType.Double
                    : e > 80
                    ? c.FoodType.FirstFood
                    : e > 60
                    ? c.FoodType.SecondFood
                    : c.FoodType.ThirdFood;
            }),
            (e.GetFoodScoreByType = function (e) {
                return e == c.FoodType.Magnet
                    ? 0
                    : e == c.FoodType.Double
                    ? 0
                    : e == c.FoodType.FirstFood
                    ? i.default.GameConfigData.FirstFoodFraction
                    : e == c.FoodType.SecondFood
                    ? i.default.GameConfigData.SecondFoodFraction
                    : e == c.FoodType.ThirdFood
                    ? i.default.GameConfigData.ThirdFoodFraction
                    : e == c.FoodType.Shit
                    ? i.default.GameConfigData.ShitFraction
                    : e == c.FoodType.StoreFood
                    ? i.default.GameConfigData.StoreFoodFraction
                    : void 0;
            }),
            (e.prototype.ResetData = function () {
                var e;
                if (
                    !(
                        (e =
                            1 == a.default.randomFrom(0, 1)
                                ? game.appFacade.retrieveProxy(r.default.NAME).rankVO.rankList
                                : game.appFacade.retrieveProxy(s.default.NAME).rankVO.rankList).length < 15
                    ) &&
                    e
                ) {
                    for (var t = [], o = 0; o < e.length; o++) {
                        var n = e[o],
                            l = a.default.parseObject(n.extendParams),
                            d = {name: "", icon: ""};
                        (d.name = l.nickName),
                            (d.icon = l.avatarUrl),
                            d.name != c.default.instance.UserName && t.push(d);
                    }
                    if (t)
                        for (o = 0; o < i.default.GameConfigData.SnakeMapNumber + 1; o++) {
                            var u = a.default.randomFrom(0, t.length - 1);
                            if (!t[u]) break;
                            this.AIList.push(t[u]), t.splice(u, 1);
                        }
                }
            }),
            (e.prototype.GetAIName = function (e) {
                return 0 != this.AIList.length && this.AIList[e] ? this.AIList[e].name : window.GetAIName(1, "all");
            }),
            (e.prototype.getIconByAIName = function (e) {
                if ((0 == this.AIList.length && this.ResetData(), 0 == this.AIList.length)) return "";
                for (var t = 0; t < this.AIList.length; t++) if ((a = this.AIList[t]) && a.name == e) return a.icon;
                if (this.AIIcon[e]) return this.AIIcon[e];
                for (t = 0; t < this.AIList.length; t++) {
                    var o = this.AIList[t],
                        n = !0;
                    for (var i in this.AIIcon) {
                        var a;
                        Object.prototype.hasOwnProperty.call(this.AIIcon, i) &&
                            (a = this.AIIcon[i]) == o.icon &&
                            (n = !1);
                    }
                    if (n) return (this.AIIcon[e] = o.icon), this.AIIcon[e];
                }
            }),
            (e.Debug = !1),
            (e._instance = null),
            (e.GameTimer = 180),
            (e.SNAKE_SPEED_DANCE = 15),
            (e.SNAKE_BODY_SIZE = 39),
            (e.SNAKE_BODY_DANCE = 3),
            (e.CELL_TIME = 0.016),
            e
        );
    })();
n.default = l;
